import sys
ins = (tok for tok in sys.stdin.readlines())
n = int(next(ins))
names = []
for _ in range(n):
names.append(next(ins).split())
order = [int(tok)-1 for tok in next(ins).split()]
f,l = names[order[0]]
if f <= l:
prev_handle = f
else:
prev_handle = l
feasible = True
for i in range(1, n):
f,l = names[order[i]]
if f <= l:
first = f
second = l
else:
first = l
second = f
if prev_handle < first:
prev_handle = first
elif prev_handle < second:
prev_handle = second
else:
print("NO")
feasible = False
break
if feasible:
print("YES")
13 Reasons Why | Friend's Relationship |
Health of a person | Divisibility |
A. Movement | Numbers in a matrix |
Sequences | Split houses |
Divisible | Three primes |
Coprimes | Cost of balloons |
One String No Trouble | Help Jarvis! |
Lift queries | Goki and his breakup |
Ali and Helping innocent people | Book of Potion making |
Duration | Birthday Party |
e-maze-in | Bricks Game |
Char Sum | Two Strings |
Anagrams | Prime Number |
Lexical Sorting Reloaded | 1514A - Perfectly Imperfect Array |
580A- Kefa and First Steps | 1472B- Fair Division |